home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Views / Canvas / PortMap.cp < prev    next >
Text File  |  2000-06-23  |  3KB  |  116 lines

  1. // PortMap.cp
  2.  
  3. #ifndef PortMap_h
  4. #include "PortMap.h"
  5. #endif
  6. #ifndef Overflow_h
  7. #include "Overflow.h"
  8. #endif
  9. #ifndef MinMax_h
  10. #include "MinMax.h"
  11. #endif
  12.  
  13. int16 PortMap::HorizontalToScreen( int32 x ) const
  14.   {
  15.     Assert( CanSubtract( x, offScreen.left ) );
  16.     Assert( x - offScreen.left <= maxint16 - int32(onScreen.left) );
  17.     Assert( x - offScreen.left >= minint16 - int32(onScreen.left) );
  18.  
  19.     return x - offScreen.left + onScreen.left;
  20.   }
  21.  
  22. int16 PortMap::VerticalToScreen( int32 y ) const
  23.   {
  24.     Assert( CanSubtract( y, offScreen.top ) );
  25.     Assert( y - offScreen.top <= maxint16 - int32(onScreen.top) );
  26.     Assert( y - offScreen.top >= minint16 - int32(onScreen.top) );
  27.  
  28.     return y - offScreen.top + onScreen.top;
  29.   }
  30.  
  31. int32 PortMap::HorizontalFromScreen( int16 x ) const
  32.   {
  33.     Assert( CanAdd( int32(x) - onScreen.left, offScreen.left ) );
  34.     return int32(x) - onScreen.left + offScreen.left;
  35.   }
  36.  
  37. int32 PortMap::VerticalFromScreen( int16 y ) const
  38.   {
  39.     Assert( CanAdd( int32(y) - onScreen.top, offScreen.top ) );
  40.     return int32(y) - onScreen.top + offScreen.top;
  41.   }
  42.  
  43. PointObject PortMap::ToScreen( Point32 p ) const
  44.   {
  45.     return PointObject( HorizontalToScreen( p.h ),
  46.                               VerticalToScreen( p.v ) );
  47.   }
  48.  
  49. Point32 PortMap::FromScreen( PointObject p ) const
  50.   {
  51.     return Point32( HorizontalFromScreen( p.h ),
  52.                          VerticalFromScreen( p.v ) );
  53.   }
  54.  
  55. Rectangle PortMap::ToScreen( Rectangle32 r ) const
  56.   {
  57.     return Rectangle( HorizontalToScreen( r.left ),
  58.                             VerticalToScreen( r.top ),
  59.                             HorizontalToScreen( r.right ),
  60.                             VerticalToScreen( r.bottom ) );
  61.   }
  62.  
  63. Rectangle32 PortMap::FromScreen( Rectangle r ) const
  64.   {
  65.     return Rectangle32( HorizontalFromScreen( r.left ),
  66.                               VerticalFromScreen( r.top ),
  67.                               HorizontalFromScreen( r.right ),
  68.                               VerticalFromScreen( r.bottom ) );
  69.   }
  70.  
  71. void PortMap::RestrictOnScreen( Rectangle restriction )
  72.   {
  73.     restriction &= onScreen;
  74.     offScreen = FromScreen( restriction );
  75.     onScreen = restriction;
  76.   }
  77.  
  78. void PortMap::RestrictOffScreen( Rectangle32 restriction )
  79.   {
  80.     restriction &= offScreen;
  81.     onScreen = ToScreen( restriction );
  82.     offScreen = restriction;
  83.   }
  84.  
  85. void PortMap::Submap( Rectangle32 area )
  86.   {
  87.     Rectangle32 intersection = area & offScreen;
  88.     onScreen = ToScreen( intersection );
  89.     offScreen = intersection - area.TopLeft();
  90.   }
  91.  
  92. void PortMap::SliceHorizontally( Range32 verticalRange )
  93.   {
  94.     Rectangle32 intersection( offScreen.left,
  95.                                       Max( offScreen.top, verticalRange.Start() ),
  96.                                       offScreen.right,
  97.                                       Min( offScreen.bottom, verticalRange.End() ) );
  98.     onScreen = ToScreen( intersection );
  99.     offScreen = intersection - Point32( 0, verticalRange.Start() );
  100.   }
  101.  
  102. void PortMap::SliceVertically( Range32 horizontalRange )
  103.   {
  104.     Rectangle32 intersection( Max( offScreen.left, horizontalRange.Start() ),
  105.                                       offScreen.top,
  106.                                       Min( offScreen.right, horizontalRange.End() ),
  107.                                       offScreen.bottom );
  108.     onScreen = ToScreen( intersection );
  109.     offScreen = intersection - Point32( horizontalRange.Start(), 0 );
  110.   }
  111.  
  112. void PortMap::Scroll( Point32 distance )
  113.   {
  114.     offScreen += distance;
  115.   }
  116.